<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <script type="text/javascript">
        // 初始化页面下拉和单选框
        var data1 = [];
        $(function () {
            $.ajax({
                type : "post",
                url : "/system/menu/getMenuTree",
                success : function(data, status) {
                    data1 = data;
                },
                error : function() {

                },
            });

            $("#txt_departmentname").click(function() {
                console.log(data1);
                var options = {
                    bootstrap2 : false,
                    showTags : true,
                    levels : 5,
                    showCheckbox : true,
                    data : data1,
                    onNodeSelected : function(event, data) {
                        $("#txt_departmentname").val(data.text);
                        $("#treeview").hide();
                    }
                };

                $('#treeview').treeview(options);
            });
        });




        /**
         * 保存
         */
        $('#btn_save').click(function () {
            //1. 表单验证
            var rs=$('#form').data("bootstrapValidator").isValid();
            if (rs) {
                //2 如果验证成功发送ajax请求保存角色
                var data = $("#form").serialize();
                var options = {
                    url: '/system/help/update',
                    type: 'post',
                    dataType: 'json',
                    data: $('#form').serialize(),
                    success: function (data) {
                        if (data) {
                            showAlert('修改成功!',function () {
                                $('#table').bootstrapTable('refresh', {silent: true})
                                $('#modal').modal('hide')
                            });
                        }
                    }
                };
                $.ajax(options);
            }
        });



    </script>
</head>
<body class="fixed-left">
<form id="form"  class="form-horizontal">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
        <h5 class="modal-title" id="exampleModalLabel">添加操作菜单</h5>
    </div>
    <div class="modal-body">
        <div class="container">

            <div class="form-group">
                <label class="col-sm-2 control-label">菜单名称</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" name="question" placeholder="菜单名称"  required data-bv-notempty-message="菜单名称是必填的并且不能为空" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">上级菜单</label>
                <div class="col-sm-10">
                    <input type="text" id="txt_departmentname" name="txt_departmentname" class="form-control dropdown" value="" onclick="$('#treeview').show()" placeholder="分类名称" required data-bv-notempty-message="上级菜单是必填的并且不能为空">
                    <div id="treeview" style="display: none;"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">菜单URL</label>
                <div class="col-sm-10">
                    <input class="form-control" name="answer" type="text"  required data-bv-notempty-message="菜单URL是必填的并且不能为空" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">授权标识</label>
                <div class="col-sm-10">
                    <input class="form-control" name="answer" type="text"  required data-bv-notempty-message="授权标识是必填的并且不能为空" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">排序号</label>
                <div class="col-sm-10">
                    <input class="form-control" name="answer" type="number"  required data-bv-notempty-message="答案是必填的并且不能为空" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">菜单图标</label>
                <div class="col-sm-10">
                    <input class="form-control" name="answer" type="text"  />
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button id="btn_save" type="button" class="btn btn-primary">保存</button>
        <button type="reset" class="btn btn-secondary" >重置</button>
    </div>
</form>
</body>
</html>